using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LitTools;
using UnityEngine.UI;
using UnityEngine.EventSystems;

public class BattlePanel : UIBase
{
    public override float RemainTime => -1;
    public override int Layer => 0;
    public override string Path => "Prefab/UI/BattlePanel";

    private Image img_controller;
    private bool isDraging;
    public override void OnInit(GameObject ui)
    {
        img_controller = ui.transform.Find("img_controller").GetComponent<Image>();

        img_controller.OnPointerClick(OnControllerClick);
        img_controller.OnBeginDrag(OnControllerBeginDrag);
        img_controller.OnDrag(OnControllerDrag);
        img_controller.OnEndDrag(OnControllerEndDrag);
    }

    #region lifetime
    public override void OnDestroy()
    {

    }

    public override void OnHide()
    {

    }

    public override void OnShow()
    {

    }

    public override void OnUpdate()
    {

    }
    #endregion

    private void OnControllerClick(PointerEventData eventData)
    {
        if (isDraging) return;
        MessageManager.Instance.SendMessage(Message.ControllerClick, eventData.position);
    }

    private void OnControllerBeginDrag(PointerEventData eventData)
    {
        isDraging = true;
        MessageManager.Instance.SendMessage(Message.ControllerBeginDrag, eventData.position);
    }

    private void OnControllerDrag(PointerEventData eventData)
    {
        MessageManager.Instance.SendMessage(Message.ControllerDrag, eventData.position);
    }

    private void OnControllerEndDrag(PointerEventData eventData)
    {
        isDraging = false;
        MessageManager.Instance.SendMessage(Message.ControllerEndDrag, eventData.position);
    }
}
